# conding=utf-8
import sys
import pandas as pd
from paddleocr import PaddleOCR




def get_value_by_OCR(img_path,match_str):
    '''
    将图片中的文字识别出来，并返回 第一个左上角顶点坐标
    :param img_path:识别图片
    :param match_str:用匹配字符串,以“|”分割
    :return:
    '''
    ocr = PaddleOCR(use_angle_cls=True, lang='ch', use_gpu=True,show_log=False,code='utf-8')
    result = ocr.ocr(img_path, cls=True)  # cls=True 表示启用方向分类器
    ocr_all_datas = result[0]
    center_x =-1
    center_y =-1
    print(f"匹配字：{match_str}")
    if ocr_all_datas:
        for i in range(len(ocr_all_datas)):
            wenzi = ocr_all_datas[i][1][0]
            match_strs = match_str.split("|")
            for ms in match_strs:
                if ms in wenzi:    # 满足其一即可
                    center_x = ocr_all_datas[i][0][0][0]
                    center_y = ocr_all_datas[i][0][0][1]

                    break
        print(f"坐标|{center_x}|{center_y}")



if __name__ == '__main__':
    if len(sys.argv) < 2:
        print("Usage: python script_name.py <image_path> [<match_str1> <match_str2> ...]")
        sys.exit(1)
    img_path = sys.argv[1]
    match_str = sys.argv[2]
    get_value_by_OCR(img_path,match_str)